import axios from 'axios'

const request = axios.create({
  baseURL: 'https://conduit.productionready.io'
})

export default ({ store }) => {
  request.interceptors.request.use((config) => {
    const { token } = store.state.user || {}
    !!token && (config.headers.Authorization = `Token ${token}`)
    return config
  }, (error) => {
    return Promise.reject(error)
  })
}
